package com.longge;

import java.util.ArrayList;
import java.util.List;

public class GetGoodIndices {

    public List<Integer> getGoodIndices(int[][] variables, int target) {
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < variables.length; i++) {
            int a = variables[i][0];
            int b = variables[i][1];
            int c = variables[i][2];
            int m = variables[i][3];
            int calculatedValue = (int)(Math.pow(a, b) % m) % 10;
            if (Math.pow(calculatedValue, c) % m == target) {
                result.add(i);
            }
        }
        return result;
    }
}
